package model

import (
	"auth/model/entity"
)

type RoleCreateRequest struct {
	Name string `json:"name" validate:"required"`

	PermissionIds []int64 `json:"permission_ids"`
}

type RoleUpdateRequest struct {
	ID int64 `json:"id"`

	Name string `json:"name" validate:"required"`

	PermissionIds []int64 `json:"permission_ids"`

	CreatedAt int64 `json:"created_at"`
}

type RoleListRequest struct {
	Index int `json:"index"`
	Size  int `json:"size"`

	Name string `json:"name" validate:"required"`

	PermissionIds []int64 `json:"permission_ids"`
}

type RoleListResponse struct {
	Total int         `json:"total"`
	Data  []*RoleInfo `json:"data"`
}

type RoleInfo struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`

	PermissionIds []int64 `json:"permission_ids"`

	Type int `json:"type"`

	CreatedAt int64 `json:"created_at"`

	UpdatedAt int64 `json:"updated_at"`
}

type RoleDeleteRequest struct {
	ID int64 `json:"id"`
}

func RolesEntityToDto(roles []*entity.Role) []*RoleInfo {
	out := make([]*RoleInfo, 0, len(roles))
	for _, c := range roles {
		out = append(out, RoleEntityToDto(c))
	}
	return out
}

func RoleEntityToDto(e *entity.Role) *RoleInfo {
	return &RoleInfo{

		Name: e.Name,

		PermissionIds: e.PermissionIds,

		Type: e.Type,

		CreatedAt: e.CreatedAt,

		UpdatedAt: e.UpdatedAt,
	}
}
